var songApp=angular.module('songapp',['ionic','globalapp']);
songApp.directive('ckHandel',function($compile){
	var _html ='<div class="Hbox"><div class="handle">';
	_html += '<p><span ng-click="close()">X<span></p>';
	_html += '<ul class="list-group">';
	_html += '<li class="list-group-item"><a>喜欢</a></li>';
	_html += '<li class="list-group-item"><a ng-click="down($index)">下载歌曲</a></li>';
	_html += '<li class="list-group-item"><a>分享</a></li>';
	_html += '<li class="list-group-item"><a>添加到</a></li></ul></div></div>';
	return{
		restrict:'AE',
		template:_html,
		link:function(scope,element,attr){
			scope.close=function(){
				$('ck-handel').hide();
			}
			scope.down=function(){
				window.location.href=attr.downurl
			}
		}
	}
})
songApp.controller('songcontroller',function($scope,$compile,$http){
	$scope.handel=function(surl,index,event){
		event.stopPropagation();
		if($('ck-handel')&&$('ck-handel').is(':hidden')){
			$('ck-handel').show().attr('downurl',surl);
		}else{
			$('<ck-handel downurl='+surl+'></ck-handel>').appendTo('body');
			$compile('ck-handel')($scope)
			
		}
		
	};
	//请求歌曲
	$http({
		url:common.baseurl+'213-4',
		method:'get',
		params:{'showapi_appid':26918,
		'showapi_sign':'c232d0da8fa14d598a3d703f6315e451', 
		'topid':5,
		'page':0
		}
	}).success(function(data){
		console.log(data);
		$scope.songlist=data.showapi_res_body.pagebean.songlist;
		$scope.minsrc=$scope.songlist[0].albumpic_small;
		$scope.songname=$scope.songlist[0].songname;
		$scope.singer=$scope.songlist[0].singername;
		$scope.currSong=$scope.songlist[0].url;
		$("<source src=''>").prop('src',$scope.currSong).appendTo('audio')

	})
	$scope.play=function(index,event){
		event.stopPropagation();
		console.log($scope.songlist[index].url);
		$("source").prop('src',$scope.songlist[index].url).closest('audio')[0].play();
	}
	//默认第一首
	$scope.currentPlay=function(){
		$('audio')[0].play();
		
	}
	
	
})
